package com.dmz.proxy.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;


/**
 * <p>
 * WebMvcConfig配置类
 * </p>
 *
 * @author lee
 * @since 2023-05-30 13:02
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/{spring:\\w+}").setViewName("forward:/index.html");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
/*        List<String> excludePath = new ArrayList<String>();
        // 开放登录接口
        excludePath.add("/dev-api/**");
        // 开放登录接口
        excludePath.add("/railway");
        // 开放前端静态资源和静态页面
        excludePath.add("/bbcpclient/**");
        // 开放前端静态资源和静态页面
        excludePath.add("/bbcpclient/ttzjjg/**");*/
    }

    /**
     * 配置静态资源映射
     *
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置静态资源映射
        registry.addResourceHandler("/bbcpclient/**").addResourceLocations("classpath:/public/");
        registry.addResourceHandler("/bbcpclient/assets/**").addResourceLocations("classpath:/public/assets/");
        // 添加Vue前端资源的映射
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/static/");

        // 如果Vue路由使用的是history模式，需要将任何路径都重定向到index.html
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/public/");
    }

}
